package cn.kgcnews.filter;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import cn.kgcnews.pojo.User;

public class ManageFilter implements Filter {

	@Override
	public void destroy() {
		// TODO Auto-generated method stub

	}

	@Override
	public void doFilter(ServletRequest req, ServletResponse res,
			FilterChain chain) throws IOException, ServletException {
		System.out.println("进入管理者锅炉器");
		  String userName="";
		    //权限验证
		  HttpServletRequest req1=(HttpServletRequest)req;
		  HttpServletResponse res1=(HttpServletResponse)res;
		  res1.setContentType("text/html;charset=utf-8");
		  HttpSession session=req1.getSession();
		  PrintWriter out = res1.getWriter();
		    Object obj=session.getAttribute("loginUser");
		    if(obj==null){
		        out.println("<script>alert('您没有权限进入......');location.href='../index.jsp';</script>");
		    }else{
		        if(obj instanceof User){
		           User user=(User)obj;
		           userName=user.getUserName();  
		        }
		    }
		    chain.doFilter(req, res);
	}

	@Override
	public void init(FilterConfig arg0) throws ServletException {
		// TODO Auto-generated method stub

	}

}
